﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;



using PowerCreator.LMS.Paper.Entiry;
using PowerCreator.LMS.Web.Paper;
using PowerCreator.LMS.Common.Script;


public partial class sysadmin_QuestionManager_AddPaperInfo : PowerCreator.LMS.Web.Base.BasePage
{
    //ManagerPaperInfo manager = new ManagerPaperInfo();

    ManagerPaper objManagerPaper = new ManagerPaper();
    //ManagerUserInfo userManager = new ManagerUserInfo();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!GetRole(Role.AddPaper))
        //{
        //    Script.ShowAndHistory("您没有添加试卷的权限!", -1);
        //    return;
        //}
        if (!IsPostBack)
        {
            ViewState["UserID"] = GetCreatedByInfo().UserID;
            BindRpt();
            InitPage();
            //BinderDDL();
        }
    }

    //private void BinderDDL()
    //{
    //    DataTable dt = new DataTable();
    //    dt = userManager.Query("");
    //    ddlUserList.DataSource = dt;
    //    ddlUserList.DataTextField = "UserName";
    //    ddlUserList.DataValueField = "UserID";
    //    ddlUserList.DataBind();
    //}
    /// <summary>
    /// 绑定培训班信息
    /// </summary>
    private void BindRpt()
    {
        PowerCreator.LMS.Web.DL.Project.TOClass obj = new PowerCreator.LMS.Web.DL.Project.TOClass();

        
        //DataTable dt = obj.Query(" Broswer=1 ");
        //chk_FKNewClaIDlist.DataSource = dt;
        //chk_FKNewClaIDlist.DataTextField = "Name";
        //chk_FKNewClaIDlist.DataValueField = "class_id";
        //chk_FKNewClaIDlist.DataBind();
    }

    protected override void InitPage()
    {
        //lbl_AddPaperInfo_Title.Text = GetLanageValueByKey("lab_AddPaperInfo_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_AddPaperInfo_PaperName.Text = GetLanageValueByKey("lab_AddPaperInfo_PaperName", PowerCreator.LMS.Language.LanagetItemType.Page);
        //rdbtn_ok.Text = GetLanageValueByKey("lab_AddPaperInfo_CommonPaper", PowerCreator.LMS.Language.LanagetItemType.Page);
        //rdbtn_no.Text = GetLanageValueByKey("lab_AddPaperInfo_TestPaper", PowerCreator.LMS.Language.LanagetItemType.Page);
        //btn_AddPaperInfo_SaveNext.Text = GetLanageValueByKey("btn_AddPaperInfo_SavePaperAndSelect", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }
    private bool PageCheck()
    {

        if (string.IsNullOrEmpty(txtPaperName.Text.Trim()) | string.IsNullOrEmpty(txt_StartTime.Text.Trim()) | string.IsNullOrEmpty(txt_EndTime.Text.Trim()))
        {
            Script.Alert(this, "msg", GetLanageValueByKey("AddPaper_msg13", PowerCreator.LMS.Language.LanagetItemType.Page));
            return false;
        }

        string search = " PaperResearch_Name=" + "'" + txtPaperName.Text + "'";
        if (objManagerPaper.CountPaperResearch(search) != 0)
        {
            Script.Alert(this, "msg", GetLanageValueByKey("Msg_AddPaperInfo_checkmsg6", PowerCreator.LMS.Language.LanagetItemType.Page));
            return false;

        }
        return true;

    }
    protected void btnSaveNext_Click(object sender, EventArgs e)
    {
        //保存并下一步


        if (!PageCheck())
        {
            return;
        }


        VOPaperResearch info = new VOPaperResearch();

        info.PaperResearch_Name = txtPaperName.Text;


        if (rdbtn_ok.Checked)
        {
            info.PaperResearch_SeeState = 1;
        }
        else
        {
            info.PaperResearch_SeeState = 0;
        }
        if (rdbtn_ShowOK.Checked)
        {
            info.PaperResearch_ShowState = 1;
        }
        else
        {
            info.PaperResearch_ShowState = 0;
        }
        info.PaperResearch_selecttype = "1";
        info.PaperResearch_BuildState = 0;

        info.PaperResearch_StartTime = Convert.ToDateTime(txt_StartTime.Text);
        info.PaperResearch_EndTime = Convert.ToDateTime(txt_EndTime.Text);
        info.PaperRearch_FKClassID = getTrainClaIDlist();
                
        int pid = 0;
        objManagerPaper.CreatePaperResearch(info,ref pid);
        if (pid != 0)
            ViewState.Add("PaperID",pid.ToString());


       string url = "SelectQuestion.aspx?p=" + ViewState["PaperID"].ToString() ;


        Script.RedirectURL(url);
    }

    private string getTrainClaIDlist()
    {
        string trainClaIDlist = "-1,";

        //for (int j = 0; j < chk_FKNewClaIDlist.Items.Count; j++)
        //{
        //    if (chk_FKNewClaIDlist.Items[j].Selected)
        //    {
        //        trainClaIDlist += chk_FKNewClaIDlist.Items[j].Value + ",";
        //    }
        //}
        trainClaIDlist += "0";
        if (trainClaIDlist == "-1,0")
            trainClaIDlist = "";
        return trainClaIDlist;
    }

    protected void rdbtn_ok_CheckedChanged(object sender, EventArgs e)
    {
       
    }
    protected void rdbtn_no_CheckedChanged(object sender, EventArgs e)
    {

    }
    protected void rdbtn_ShowOK_CheckedChanged(object sender, EventArgs e)
    {

    }
    protected void rdbtn_ShowNO_CheckedChanged(object sender, EventArgs e)
    {

    }
}
